package com.example.reader.controller;

import com.example.reader.common.Result;
import com.example.reader.entity.Orders;
import com.example.reader.service.OrderService;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/orders")
public class OrderController {
    @Autowired
    private OrderService orderService;

    //订阅书籍
    @PostMapping("/add")
    public Result add(@RequestBody Orders orders){
        orderService.add(orders);
        return Result.success();
    }
    //分页查看订阅书籍
    @GetMapping("/selectPage")
    public Result selectPage(Orders orders, @Param("pageNum") Integer pageNum, @Param("pageSize") Integer pageSize){
        PageInfo pageInfo=orderService.selectPage(orders,pageNum,pageSize);
        return Result.success(pageInfo);
    }

    //取消借阅
    @PutMapping("/update")
    public Result update(@RequestBody Orders orders) {
        orderService.updateById(orders);
        return Result.success();
    }
}
